import numpy as np
from math import sqrt

def get_mean(l):
    "get the mean of a list efficiently with NumPy"
    N = len(l)
    narray = np.array(l)
    sum = narray.sum()
    mean = sum / N
    return mean


def get_var(l):
    "get the variance of a list efficiently with NumPy"
    N = len(l)
    mean = get_mean(l)
    narray = np.array(l)
    narray2 = narray * narray
    sum2 = narray2.sum()
    var = sum2 / N - mean**2
    return var


def get_stdev(l):
    "get the standard deviation of a list with get_var() and math.sqrt()"
    var = get_var(l)
    stdev = sqrt(var)
    return stdev


def in_chebyshevs_interval(x, mean, stdev, pct):
    "judge the input value 1"
    "x: sample; mean: average value; stdev: standard deviation; pct: percentage"
    "根据参数长度数值集的计算的阈值结果做判断"
    m = int(sqrt(1 / (1 - pct * 0.01)))
    is_in_chebyshevs_interval = 0
    if mean - m * stdev <= x and x <= mean + m * stdev:
        is_in_chebyshevs_interval = 1
    return is_in_chebyshevs_interval